//package com.ljx.sso.service;
//
//import com.ljx.entity.EmpInfo;
//import com.ljx.entity.Permission;
//import com.ljx.sso.feign.EmpInfoFeign;
//import com.ljx.sso.feign.PermissionFeign;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Service;
//
//import java.util.Collection;
//import java.util.List;
//import java.util.stream.Collectors;
//
///**
// * @author LJX
// * @Description: TODO
// * @Date: 2023/2/22 20:48
// * @Version 1.0
// */
//@Service
//public class UserService1 implements UserDetailsService {
//
//	@Autowired
//	private EmpInfoFeign empInfoFeign;
//
//	@Autowired
//	private PermissionFeign permissionFeign;
//
//	@Override
//	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//
//		//1.根据用户名查询用户信息
//		EmpInfo empInfo = empInfoFeign.getByName(username);
//		if(empInfo!=null){
//			//2.根据当前用户查询该用户具有的权限。
//			List<Permission> permissions = permissionFeign.getPermissionByUserid(empInfo.getId());
//			Collection<SimpleGrantedAuthority> authorities = permissions.stream()
//					.filter(item->item.getCode()!=null)
//					.map(item->new SimpleGrantedAuthority(item.getCode()))
//					.collect(Collectors.toList());
//			User user = new User(empInfo.getEname(),empInfo.getPassword(),authorities);
//			return user;
//		}
//		return null;
//	}
//}
